package com.bh.extend.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.bh.common.exception.ServiceException;
import com.bh.common.utils.DateUtils;
import com.bh.common.utils.SecurityUtils;
import com.bh.extend.domain.JcLedEvaluation;
import com.bh.extend.mapper.JcLedEvaluationMapper;
import com.bh.extend.service.IJcLedEvaluationService;
import com.bh.extend.vo.JcLedEvaluationVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Arrays;
import java.util.Date;
import java.util.List;

/**
 * 订单评价Service业务层处理
 *
 * @author slx
 * @date 2023-03-26
 */
@Service
public class JcLedEvaluationServiceImpl extends ServiceImpl<JcLedEvaluationMapper, JcLedEvaluation> implements IJcLedEvaluationService {
    @Autowired
    private JcLedEvaluationMapper jcLedEvaluationMapper;

    /**
     * 查询订单评价
     *
     * @param id 订单评价主键
     * @return 订单评价
     */
    @Override
    public JcLedEvaluation selectJcLedEvaluationById(Long id) {
        return jcLedEvaluationMapper.selectById(id);
    }

    @Override
    public JcLedEvaluation selectJcLedEvaluationByOrderId(Long ledId) {
        return jcLedEvaluationMapper.selectJcLedEvaluationByLedId(ledId);
    }

    /**
     * 查询订单评价列表
     *
     * @param jcLedEvaluation 订单评价
     * @return 订单评价
     */
    @Override
    public List<JcLedEvaluation> selectJcLedEvaluationList(JcLedEvaluation jcLedEvaluation) {
        return jcLedEvaluationMapper.selectJcLedEvaluationList(jcLedEvaluation);
    }

    @Override
    public List<JcLedEvaluationVo> selectJcLedEvaluationVoList(JcLedEvaluationVo jcLedEvaluation) {
        return jcLedEvaluationMapper.selectJcLedEvaluationVoList(jcLedEvaluation);
    }

    /**
     * 新增订单评价
     *
     * @param jcLedEvaluation 订单评价
     * @return 结果
     */
    @Override
    public int insertJcLedEvaluation(JcLedEvaluation jcLedEvaluation) {
        JcLedEvaluation evaluation = jcLedEvaluationMapper.selectJcLedEvaluationByLedId(jcLedEvaluation.getLedId());
        if (evaluation != null) {
            throw new ServiceException("已经评价过了，不能重复评价！");
        }
        jcLedEvaluation.setEvaluationDate(new Date());
        jcLedEvaluation.setCreateBy(SecurityUtils.getUsername());
        jcLedEvaluation.setCreateTime(DateUtils.getNowDate());
        return jcLedEvaluationMapper.insert(jcLedEvaluation);
    }

    /**
     * 修改订单评价
     *
     * @param jcLedEvaluation 订单评价
     * @return 结果
     */
    @Override
    public int updateJcLedEvaluation(JcLedEvaluation jcLedEvaluation) {
        return jcLedEvaluationMapper.updateById(jcLedEvaluation);
    }

    /**
     * 批量删除订单评价
     *
     * @param ids 需要删除的订单评价主键
     * @return 结果
     */
    @Override
    public int deleteJcLedEvaluationByIds(Long[] ids) {
        return jcLedEvaluationMapper.deleteBatchIds(Arrays.asList(ids));
    }

    /**
     * 删除订单评价信息
     *
     * @param id 订单评价主键
     * @return 结果
     */
    @Override
    public int deleteJcLedEvaluationById(Long id) {
        return jcLedEvaluationMapper.deleteById(id);
    }
}
